export default computedTotalCapacity;

function computedTotalCapacity(content, areaTypes) {
  let capacity = { value: 0, details: [] };
  for (let i = 0; i < areaTypes.length; i++) {
    capacity.details.push({
      areaType: areaTypes[i].areaType,
      areaTypeName: areaTypes[i].areaTypeName,
      totalCapacity: areaTypes[i].totalCapacity,
      totalCapacityDiscounted: areaTypes[i].totalCapacity,
      originalCapacityAccumulated: 0,
      currentCapacityAccumulated: 0,
      discountingRatio: 1,
      limitedCapacity: 0,
    });
  }
  for (let i = 0; i < content.length; i++) {
    let corn = content[i];
    for (let j = 0; j < capacity.details.length; j++) {
      let cell = capacity.details[j];
      if (cell.areaType === corn.areaType) {
        cell.currentCapacityAccumulated += corn.currentCapacity;
        cell.originalCapacityAccumulated += corn.originalCapacity;
        if (cell.totalCapacity == 0) {
          cell.limitedCapacity = cell.currentCapacityAccumulated;
        } else {
          cell.discountingRatio =
            cell.currentCapacityAccumulated / cell.originalCapacityAccumulated;
          cell.totalCapacityDiscounted = Math.round(
            cell.totalCapacity * cell.discountingRatio
          );
          cell.limitedCapacity = Math.min(
            cell.currentCapacityAccumulated,
            cell.totalCapacityDiscounted
          );
        }
      }
    }
  }
  capacity.value = 9999;
  for (let i = 0; i < capacity.details.length; i++) {
    capacity.value = Math.min(
      capacity.value,
      capacity.details[i].limitedCapacity
    );
  }
  return capacity;
}

/* ----------------------------------------------------------------

{
  "models": [
    "01",
    "08",
    "10"
  ],
  "areaCode": 1,
  "areaName": "1区",
  "areaType": 1,
  "airportCount": 1,
  "capacityRatio": 1,
  "currentCapacity": 67,
  "weatherCoverage": 0,
  "originalCapacity": 67,
  "weatherIntensity": 0,
  "raletedGatePoints": [],
  "weatherConditions": [],
  "weatherProbability": 0
}

---------------------------------------------------------------- */
